<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-nested" prefix="nested" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="css/global.css" type="text/css" />
    <link rel="stylesheet" href="css/forms.css" type="text/css" />
    <link rel="stylesheet" href="css/toolbar.css" type="text/css" />
    <script type="text/javascript">
    	function js_deleteClient(index, listSize) {
    		if(listSize > 1) {
				deleteClientForm[index].submit();
    		} else {
    			deleteClientForm.submit();
    		}
    	}
    	function js_editClient(index, listSize) {
    		if(listSize > 1) {
				updateClientForm[index].submit();
    		} else {
    			updateClientForm.submit();
    		}
    	}
    </script>
    <title>TP Final: Clientes</title>
</head>
<body>
	<!-- HEADER -->
    <div class="header">
        <nav>
            <ul>
                <li><a href="#">Herramientas</a>
                    <ul>
                        <li><a href="#">Buscar trámite</a></li>
                        <li><a href="#">Buscar cliente</a></li>
                        <li><a href="#">Ver trámites</a></li>
                        <li><a href="#">Ver clientes</a></li>
                        <li><a href="#">Nuevo trámite</a></li>
                        <li><a href="#">Nuevo cliente</a></li>
                    </ul>
                </li>
                <li><a href="newClient.do">Nuevo</a></li>
                <li><a href="#">Salir</a></li>
            </ul>
        </nav>
    </div>
    <!-- MAIN BODY -->
    <div>
        <h2>Listado de Clientes</h2>
        <logic:notEmpty name="clientAddressList" scope="request">
        	<bean:size id="listSize" name="clientAddressList" scope="request" />
	        <table style="width: 100%; margin: 0 auto 0 auto; border: 1px solid black;">
	            <thead>
	                <tr>
	                    <th>Nombre</th>
	                    <th>Apellido</th>
	                    <th>Teléfono</th>
	                    <th>Email</th>
	                    <th colspan="2">Modificar</th>
	                </tr>
	            </thead>
	            <tbody>
	                <logic:iterate id="iterator" name="clientAddressList" indexId="i">
		                <html:form action="deleteClient.do" method="post">
		                	<html:hidden name="iterator" property="client.oid" />
		                </html:form>
		                <html:form action="editClient.do" method="post">
		                	<html:hidden name="iterator" property="client.oid" />
		                </html:form>
						<tr id="hoverRow">
						    <td>${iterator.client.firstName}</td>
						    <td>${iterator.client.lastName}</td>
						    <td>${iterator.client.telephone}</td>
						    <td>${iterator.client.email}</td>
						    <td><a href="#" onclick="js_deleteClient(${i}, ${listSize});">Eliminar</a></td>
						    <td><a href="#" onclick="js_editClient(${i}, ${listSize});">Editar</a></td>
						</tr>
	                </logic:iterate>
	            </tbody>
	        </table>
        </logic:notEmpty>
    </div>
    <!-- FOOTER -->
</body>
</html>